%s test
%{
    #include <iostream>
    #include <string> /* The tokens */
    #include "pkasm_parse.hpp" /* The tokens */
    extern void yyerror(const char *s);
%}
%option noyywrap yylineno
%%
;.*        { /* comment */ }
\n                      { return T_NEWLINE; }
[ \t\r]+      { /* spaces */ }
("0x"[0-9A-Za-z]+)|([0-9]+) {
    std::cout << "!integer!" << std::endl;
    if(sscanf(yytext, "%i", &yylval.number) != 1)
        fatal("error:%u: failed to convert %s to integer\n", yylineno, yytext);
    return T_INTEGER;
}
r(3[0-2]|[0-2]?[0-9]) {
    if(sscanf(yytext + 1, "%i", &yylval.number) != 1)
        fatal("error:%u: failed to convert %s to register\n", yylineno, yytext);
    return T_REGISTER;
}
:                       { return T_DOUBLE_DOT; }
,                       { return T_COMMA; }
at                      { return T_DIR_AT; }
end                     { return T_DIR_END; }
mov			            { return T_OP_MOV; }
add                     { return T_OP_ADD; }
sub                     { return T_OP_SUB; }
cmp                     { return T_OP_CMP; }
or                      { return T_OP_OR; }
xor                     { return T_OP_XOR; }
and                     { return T_OP_AND; }
neg                     { return T_OP_NEG; }
not                     { return T_OP_NOT; }
shl                     { return T_OP_SHIFTL; }
shr                     { return T_OP_SHIFTR; }
sha                     { return T_OP_SHIFTRA; }
jmpa                    { return T_OP_JUMP_ABS; }
jmpr                    { return T_OP_JUMP_REL; }
swp16                   { return T_OP_SWAP16; }
swp8                    { return T_OP_SWAP8; }
bswp                    { return T_OP_BSWAP; }
ld                      { return T_OP_LOAD; }
st                      { return T_OP_STORE; }
("ifn"("z"|"eq"))|"="   { return T_COND_EQUAL; }
("ifz"|"ifeq")|"!="  { return T_COND_NEQUAL; }
"ifl"|"<"               { return T_COND_LESS; }
"ifleq"|"<="            { return T_COND_L_EQ; }
"ifgr"|">"              { return T_COND_GREATER; }
"ifgreq"|">="           { return T_COND_GR_EQ; }
[_a-zA-Z][_a-zA-Z0-9]*  {
	yylval.label = strdup(yytext);
	return T_LABEL;
}
<<EOF>>                 { return T_DIR_END; }
. { std::cerr<< "char \'" << yytext[0] << "\'" << std::endl; ECHO; }
%%

